
<html>
<head>
  <title>PHP File Browser</title>
  <style type="text/css">
    .error{ color:red; font-weight:bold; }
    .unlink{ margin-left:1em; font-size:small; color:red;}
    .col1 {
	float: left;
	width: 310px;
	overflow: hidden;
	}

	.col2 {
	width: 800px;
	overflow: hidden;
	margin: 0 0 0 340px;
	}
    .boton {
    float:botton;
	width: 100%;
	overflow: hidden;
	
	}
  </style>
  	<script type="text/javascript" src="../javascript/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="../jquery.dropotron-1.0.js"></script>
		<script type="text/javascript" src="../init.js"></script>
		<script src="../javascript/lightbox.js"></script>
		<link rel="stylesheet" href="../jQuery/jquery-ui.css" />
	    <script src="../jQuery/jquery-1.8.3.js"></script>
	    <script src="../jQuery/jquery-ui.js"></script>		
		<script type="text/javascript" src="../javascript/cleanajax/clean-all.js"></script>
		<script type="text/javascript" src="../javascript/ownajax.js"></script>
		<script src="../ckeditor/ckeditor.js"></script>

<script type="text/javascript" >

var ARCHIVO=""; 

function setFileValue()
{
	var args = setFileValue.arguments;
	ARCHIVO=args[0];
}

function closeWin()
{
	window.close();
}

</script>
</head>
<body>
<div class="col1" id="explorer">
  <h1>Explorador de Archivos</h1>
<?php
  // Explore the files via a web interface.   
  //echo __FILE__;
  
  $htdir = "../images/news/"; //getcwd();
  //echo $htdir;
  $script = basename(__FILE__); // the name of this script
  $path   = !empty($_REQUEST['path']) ? $_REQUEST['path'] : $htdir; // the path the script should access
  $unlink = $_REQUEST['unlink'];
  
  if(!empty($unlink)){
    $unlink = realpath("$path/$unlink");
    if(is_writable($unlink) && !unlink($unlink)){
      echo "<div class=\"error\">Unable to delete file: $unlink</div>";
    }
  }
  
 // echo "<p>Browsing Location: {$path}</p>";
  
  $directories = array();
  $files       = array();
  
  // Check we are focused on a dir
  if (is_dir($path)){
    chdir($path); // Focus on the dir
    if ($handle = opendir('.')){
      while (($item = readdir($handle)) !== false) {
        // Loop through current directory and divide files and directorys
        if(is_dir($item)){
          array_push($directories, realpath($item));
        }
        else{
          array_push($files, ($item));
        }
      }
      
      closedir($handle); // Close the directory handle
    }
    else {
      echo "<p class=\"error\">Directory handle could not be obtained.</p>";
    }
  }
  else{
    echo "<p class=\"error\">Path is not a directory</p>";
  }
  
  // NO LES VAMOS A DEJAR VER LOS DIRECTORIOS
  // List the directories as browsable navigation
  /* echo "<h2>Carpetas</h2>";
  echo "<ul>";
  foreach($directories as $directory){
    echo ($directory != $path) ? "<li><a href=\"{$script}?path={$directory}\"><img src='../images/folder-icon.png' height='20' width='20' />{$directory}</a></li>" : "";
  }
  echo "</ul>"; */
  
  //echo "<h2>Archivos</h2>";
  echo "<ul>";
  foreach($files as $file){
    // Comment the next line out if you wish see hidden files while browsing
    if(preg_match("/^\./", $file) || $file == $script){continue;} // This line will hide all invisible files.
    
    $delete = is_writable($file) ? "<a class=\"unlink\" href=\"{$script}?path={$path}&unlink={$file}\">eliminar</a>" : '';
    
    echo '<li><a onclick="get(\'image_viewer.php?img=' . basename($file) . '\',\'preview\'); setFileValue(\''. basename($file).'\');" href="javascript:;" ><img src="../images/jpeg-file-icon.png" height="20" width="20" />' . $file . "</a> $delete</li>";
  }
  echo "</ul>";
?>
</div>
<div class="col2" id="preview"> <h3>Secciona un imagen para vista previa</h3></div>
<br>
<div class="boton" align="center"><a href="javascript:;" onclick="window.opener.CKEDITOR.tools.callFunction(<?php echo $_GET['CKEditorFuncNum']?>, '../images/news/'+ARCHIVO); window.opener.focus(); closeWin(); ">Seleccionar</a></div>
</body>
</html>